package com.jas.common;
//@author A0098803W
import java.util.UUID;

//@author A0098803W
/**
 * This class generates a unique ID for any event. 
 * Generally, the short ID implements the <code>UUID</code> class methods
 * with slight modification to further shorten the default length.
 *
 */
class GenerateShortUUID {
	// usage: GenerateShortUUID.next();
	private GenerateShortUUID() {
	} // singleton

	//@author A0098803W
	static String next() {
		UUID u = UUID.randomUUID();
		return toIDString(u.getMostSignificantBits())
				+ toIDString(u.getLeastSignificantBits());
	}

	//@author A0098803W
	private static String toIDString(long i) {
		char[] buf = new char[32];
		int z = 64; // 1 << 6;
		int cp = 32;
		long b = z - 1;
		do {
			buf[--cp] = DIGITS66[(int) (i & b)];
			i >>>= 6;
		} while (i != 0);
		return new String(buf, cp, (32 - cp));
	}

	//@author A0098803W
	private final static char[] DIGITS66 = { '0', '1', '2', '3', '4', '5', '6',
			'7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
			'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
			'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
			'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
			'X', 'Y', 'Z', '-', '.', '_', '~' };

}